import { Controller, Get, Post, Body, Patch, Param, Delete, UseFilters } from '@nestjs/common'
import { MenusService } from './menus.service'
import { CreateMenuDto } from './dto/create-menu.dto'
import { UpdateMenuDto } from './dto/update-menu.dto'
import { TypeormFilter } from '../filters/typeorm.filter'

@Controller('menus')
@UseFilters(new TypeormFilter())
export class MenusController {
  constructor(private readonly menusService: MenusService) {}

  @Post()
  create(@Body() createMenuDto: CreateMenuDto) {
    // 如果要做菜单名唯一性，通过传递过来的菜单名查找菜单数据，确定菜单是否存在
    return this.menusService.create(createMenuDto)
  }

  @Get()
  findAll() {
    return this.menusService.findAll()
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.menusService.findOne(+id)
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateMenuDto: UpdateMenuDto) {
    return this.menusService.update(+id, updateMenuDto)
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.menusService.remove(+id)
  }
}
